#pragma once

#include <QObject>
#include <QScopedPointer>
#include <QQueue>
#include <QUuid>

#include "task.h"

typedef QQueue<TaskData> TaskQueue;

class TaskManagerPrivate;
class TaskManager : public QObject
{
    Q_OBJECT
public:
    explicit TaskManager(QObject *parent = nullptr);
    ~TaskManager();

    bool CreateTask(const TaskData &taskdata, bool is_queue = false);
    bool CreateTaskQueue(const TaskQueue &tasks);
    bool AttachTaskQueue(const TaskData &taskdata);
    void StartTaskQueue();
    void StopTaskQueue(bool waiting = true, bool force = false);

Q_SIGNALS:
    void TaskQueueAllDone(bool success);
    void TaskStarted(const TaskData &data);
    void TaskFinished(const TaskData &data, int exitcode, const QString &contents = QString());
    void TaskError(const TaskData &data, const QString &contents);
    void TaskOutput(const TaskData &data, const QString &contents);

private:
    const QScopedPointer<TaskManagerPrivate> d_ptr;
    Q_DECLARE_PRIVATE(TaskManager)
};
